<template>
  <div id="app">
    <router-view></router-view>
    <tip></tip>
    <loading></loading>
    <back-drop></back-drop>
    <welcome></welcome>
  </div>
</template>

<script>

  import Constant from 'common/constant'
  import LocalDAO from 'common/localDAO'
  import RemoteDAO from 'common/remoteDAO'
  import Chart from 'assets/lib/chart/chart'
  import Tip from 'components/Tip'
  import Loading from 'components/Loading'
  import BackDrop from 'components/modal/BackDrop'
  import Welcome from 'components/tutorial/Welcome'
  import CommonUtil from 'common/common.util'

  export default {
    name: 'app',
    components: {
      'tip':Tip,  //文本提示框
      'loading':Loading,//loading弹窗
      'back-drop': BackDrop,  //弹窗的半黑透明遮层
      'welcome':Welcome
    },
    created: function () {
    	 // this.test()
       this.cleanStorage()
       //初始化牛人牛股的登录逻辑
       this.init()
       
    },
    mounted(){
      //打包到本地，默认根路由不起作用
      // this.$router.replace({path: '/'});
    },
    methods:{
    	 init(){
    	 	  let self = this;
          //第一次进入牛人牛股模块，进入到登录逻辑，之后直接渲染
          if(sessionStorage.getItem(Constant.flag.FIRST_IN) !== "1"){
              //查询登录状态
              this.loginInit()
          }
          //储存shareid
          LocalDAO.setShareid(self.$route.query.shareid);
          //储存页面高度
          let height = document.documentElement.getBoundingClientRect().height
          this.$store.dispatch('setHtmlHeight',height)
    	 },
       cleanStorage () {
          console.log("进入cleanStorage");
          if (sessionStorage.getItem("cleanstorage") !== '1') {
            console.log("cleanStorage的session为0");
            var usercode = localStorage.getItem("userCode")
            var appusercode = CommonUtil.getUrlParam("usercode") || this.$route.query.usercode
            if (CommonUtil.getUrlParam('cleanStorage') === '1' || this.$route.query.cleanStorage === '1') {
              console.log("cleanstorage：清除缓存啦")
              // 获取引导的缓存
              var tutorial = localStorage.getItem("tutorial")
              var dynamcTip = localStorage.getItem("isFirst")
              window.localStorage.clear()
              window.sessionStorage.clear()
              if(tutorial !== null){
                localStorage.setItem("tutorial",tutorial)
              }
              if(dynamcTip !== null){
                localStorage.setItem("isFirst",dynamcTip)
              }                                      
            }
            sessionStorage.setItem("cleanstorage", "1")
          }
       },
    	 loginInit () {
         console.log("进入login-nrngRegister");
         var nrngRegisterFlag = this.$route.query.nrngregister || CommonUtil.getUrlParam("nrngregister") || "";
         if (nrngRegisterFlag === "1") {
           //判断nickname是否为空
           var appusercode = this.$route.query.usercode || CommonUtil.getUrlParam("usercode") || "";
           var appnickname = this.$route.query.nickname || CommonUtil.getUrlParam("nickname") || "";
           if (appusercode !== "") {
             localStorage.setItem(Constant.storage.USER_CODE, appusercode);
           }
           if (appnickname !== "") {
             localStorage.setItem(Constant.storage.NICKNAME, appnickname);
           }
         }
         sessionStorage.setItem(Constant.flag.FIRST_IN,"1");
    	 },
    	 test () {
    	     let param = {
    	       relationId: '201708180000010904'
    	     }
    	     RemoteDAO.callUC12000054(param, param => {
    	     	 console.log('adeline', param)
    	     })
    	 }
    }
  }
</script>

<style lang="less">
  html, body {
    &::-webkit-scrollbar {
        display: none;
    }
  }
</style>
